package com.doodod.common.action;

import com.doodod.common.utils.MyConstants;
import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created with IDEA.
 * User: 孟波
 * Date: 14-2-12
 * Time: 下午8:59
 * To change this template use File | Settings | File Templates.
 */
public class MyStrutsFilterDispatcher extends StrutsPrepareAndExecuteFilter {
    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)req;
        String path = request.getRequestURI();
        if (!path.contains(MyConstants.API_URL_PREFIX)){
            //由struts处理
            super.doFilter(req, res, chain);
        } else {
            //跳过struts，由spring mvc处理
            chain.doFilter(req, res);
        }
    }
}
